import requests as req
from registry.authentication import Auth

class Forward:

    def __init__(self, auth: Auth) -> None:
        self.auth = auth
        pass

    def get(self, context: str, headers: dict = None, params: dict = None) -> req.Response:
        if headers is None:
            headers = {}
        headers["Authorization"] = self.auth.getBase64()
        if not context.startswith("/"):
            context = "/" + context
        return req.get(self.auth.getHost() + context, headers=headers, params=params)

    def post(self, context: str, headers: dict = None, params: dict = None, data: dict = None) -> req.Response:
        if headers is None:
            headers = {}
        headers["Authorization"] = self.auth.getBase64()
        if not context.startswith("/"):
            context = "/" + context
        return req.post(self.auth.getHost() + context, headers=headers, params=params, data=data)

    def delete(self, context: str, headers: dict = None, params: dict = None) -> req.Response:
        if headers is None:
            headers = {}
        headers["Authorization"] = self.auth.getBase64()
        if not context.startswith("/"):
            context = "/" + context
        return req.delete(self.auth.getHost() + context, headers=headers, params=params)
